﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model;
using MySql.Data.MySqlClient;
using System.Data;

namespace l1cs.server.datatables
{
    public class NPCTalkDataTable
    {
        private static Logger _log = Logger.getLogger( typeof( NPCTalkDataTable ).FullName );

        private static NPCTalkDataTable _instance;

        private Dictionary<int, L1NpcTalkData> _datatable = new Dictionary<int, L1NpcTalkData>();

        public static NPCTalkDataTable getInstance()
        {
            if ( _instance == null )
            {
                _instance = new NPCTalkDataTable();
            }
            return _instance;
        }

        private NPCTalkDataTable()
        {/*TTOK*/
            String sqlstr = "SELECT * FROM npcaction";
            using ( MySqlWrapper wrapper = new MySqlWrapper() )
            {
                foreach ( DataRow item in wrapper.GetDataTable( sqlstr ).Rows )
                {
                    L1NpcTalkData l1npctalkdata = new L1NpcTalkData();
                    l1npctalkdata.setNpcID( Convert.ToInt32( item["npcid"] ) );
                    l1npctalkdata.setNormalAction( Convert.ToString( item["normal_action"] ) );
                    l1npctalkdata.setCaoticAction( Convert.ToString( item["caotic_action"] ) );
                    l1npctalkdata.setTeleportURL( Convert.ToString( item["teleport_url"] ) );
                    l1npctalkdata.setTeleportURLA( Convert.ToString( item["teleport_urla"] ) );

                    _datatable[l1npctalkdata.getNpcID()] = l1npctalkdata;
                }
            }
            _log.config( "NPCアクションリスト " + _datatable.Count + "件ロード" );
        }

        public L1NpcTalkData getTemplate( int i )
        {/*TTOK*/
            L1NpcTalkData ret;
            _datatable.TryGetValue( i, out ret );
            return ret;
        }
    }
}
